/**
 * 2016，thor.com，all rights reserved。
 * 
 * Project：		palmmall-core
 * Filename：	SMeterInputConverter.java
 * Created：		2016年8月30日
 * Creator：		wolv
 */
package com.thor.palmmall.rest.meter.converter;

import org.springframework.core.convert.converter.Converter;

import com.thor.commons.entity.UCN;
import com.thor.commons.util.ConverterUtil;
import com.thor.palmmall.rest.meter.AMeter;
import com.thor.palmmall.spi.meter.SMeter;

/**
 * @author wolv
 *
 */
public class AMeterConverter implements Converter<SMeter, AMeter> {

  public static AMeterConverter getInstance() {
    if (instance == null)
      instance = new AMeterConverter();
    return instance;
  }

  private static AMeterConverter instance;

  private AMeterConverter() {
  }

  @Override
  public AMeter convert(SMeter source) {
    if (source == null)
      return null;

    AMeter target = new AMeter();
    target.setCode(source.getCode());
    target.setName(source.getName());
    target.setPosition(source.getPosition());
    target.setUuid(source.getUuid());
    target.setStore(UCN.newInstance(source.getStore()));
    target.setNormalPeriod(source.isNormalPeriod());
    target.setPeriodValues(
        ConverterUtil.convert(source.getPeriodValues(), APeriodValuesConverter.getInstance()));
    return target;
  }

}
